﻿using NJabber.Stream.Elements;
using NUnit.Framework;

namespace NJabber.Client.StanzaFactories
{
    [TestFixture]
    public class MessageStanzaFactoryTest
    {
        private JID receiverId = "receiver@jid.com";
        private string subject = "some-subject";
        private string messageText = "some message text";

        private MessageStanzaFactory factory;

        [SetUp]
        public void TestSetup()
        {
            factory = new MessageStanzaFactory();
        }

        [Test]
        public void CreatePersonalMessage_CreatesCorrectStanza()
        {
            MessageStanza stanza = (MessageStanza)factory.CreatePersonalMessage(receiverId, subject, messageText);

            VerifyMessageStanza(MessageStanzaType.Chat, stanza);
        }

        [Test]
        public void CreateGroupMessage_CreatesCorrectStanza()
        {
            MessageStanza stanza = (MessageStanza) factory.CreateGroupMessage(receiverId, subject, messageText);

            VerifyMessageStanza(MessageStanzaType.GroupChat, stanza);
        }

        [Test]
        public void CreateHeadlineMessage_CreatesCorrectStanza()
        {
            MessageStanza stanza = (MessageStanza)factory.CreateHeadlineMessage(receiverId, subject, messageText);

            VerifyMessageStanza(MessageStanzaType.Headline, stanza);
        }

        [Test]
        public void CreateStandaloneMessage_CreatesCorrectStanza()
        {
            MessageStanza stanza = (MessageStanza)factory.CreateStandaloneMessage(receiverId, subject, messageText);

            VerifyMessageStanza(MessageStanzaType.Normal, stanza);
        }

        private void VerifyMessageStanza(string stanzaType, MessageStanza stanza)
        {
            Assert.That(stanza.Type, Is.EqualTo(stanzaType));
            Assert.That(stanza.To, Is.EqualTo(receiverId));
            Assert.That(stanza.Subject, Is.EqualTo(subject));
            Assert.That(stanza.Body, Is.EqualTo(messageText));
        }
    }
}
